
import store from '@/store'

export default {
    inserted(el, binding) {
        const allowedRoles = binding.value
        const userRole = store.state.user?.userRole

        if (allowedRoles && Array.isArray(allowedRoles)) {
            if (!allowedRoles.includes(userRole)) {
                el.parentNode && el.parentNode.removeChild(el) // 没权限，移除按钮
            }
        } else {
            throw new Error(`使用方式错误：v-permission="['admin', 'editor']"`)
        }
    }
}
